package Q20

class Main {

}

fun main() {

}

class Solution {
    fun isValid(s: String): Boolean {
        var s = s.replace("()", "")
        s = s.replace("[]", "")
        s = s.replace("{}", "")


        return s.isEmpty()
    }
}

 class Solution2 {
    fun isValid(s: String): Boolean {
        var s = s
        while (s.contains("()") || s.contains("[]") || s.contains("{}")) {
            if (s.contains("()")) {
                s = s.replace("()", "")
            }
            if (s.contains("{}")) {
                s = s.replace("{}", "")
            }
            if (s.contains("[]")) {
                s = s.replace("[]", "")
            }
        }
        return s.length == 0
    }
}